package kiosk;

/**
 * Importeringer
 */
import kiosk.Produkt;
import kiosk.GUIKurv;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.Dimension;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.KeyListener;
import java.awt.event.KeyEvent;

/**
 * Klasse: Vindu
 * @author  RK
 * @version 1.0
 * -------------------------
 * Sist endret: 22 Mars 2010
 */
public class Vindu extends JFrame {

    private GUIKurv kurv;
    private String s;
    private JButton btn;
    private JLabel lbl;

    public Vindu()
    {
        this.initKomponenter();
    }

    private void initKomponenter()
    {
        // Innstillinger for vinduet
        this.setTitle("Kiosk");
        this.setSize(800, 400);
        this.setLocationRelativeTo(null);
        this.setVisible(true);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);

        // Layout for vinduet
        this.setLayout(new BorderLayout());

        // Kurven med salg
        kurv = new GUIKurv();
        this.add(kurv, BorderLayout.NORTH);
        kurv.addProduktTilKurv(new Produkt("Test", "1234", 20, 20, 20, 40));

        JPanel panel = new JPanel();
        panel.setLayout(new FlowLayout());

        lbl = new JLabel("test");
        this.add(lbl, BorderLayout.SOUTH);

        btn.setFocusable(false);
        this.add(btn, BorderLayout.SOUTH);

        this.setFocusable(true);

        this.addKeyListener(new KeyListener() {
            public String getString()
        {
            return s;
        }

        public void keyReleased(KeyEvent k)
        {
            if (k.VK_ENTER == k.getKeyChar())
            {
                lbl.setText(s);
            }
            else
            {
                s += k.getKeyChar();
            }
        }

        public void keyPressed(KeyEvent k)
        {
            if (k.VK_ENTER == k.getKeyChar())
            {
                lbl.setText(s);
            }
            else
            {
                s += k.getKeyChar();
            }
        }

        public void keyTyped(KeyEvent k)
        {
            if (k.VK_ENTER == k.getKeyChar())
            {
                lbl.setText(s);
            }
            else
            {
                s += k.getKeyChar();
            }
        }
        });
    }


    public static void main(String[] args)
    {
        Vindu v = new Vindu();
    }

    private class KeyLytter implements KeyListener
    {
        private String s;

        public String getString()
        {
            return this.s;
        }

        public void keyReleased(KeyEvent k)
        {
            if (k.VK_ENTER == k.getKeyChar())
            {
                this.getString();
            }
            else
            {
                this.s += k.getKeyChar();
            }
        }

        public void keyPressed(KeyEvent k)
        {

        }

        public void keyTyped(KeyEvent k)
        {

        }
    }
}
